package controllers;

import java.lang.reflect.Field;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.text.DateFormat;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonDeserializer;
import com.google.gson.JsonPrimitive;
import com.google.gson.JsonSerializer;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.reflect.TypeToken;
import play.mvc.Http.StatusCode;
import play.mvc.Scope.Session;
import play.Logger;
import play.i18n.Messages;
import play.mvc.Before;
import play.mvc.Catch;
import play.mvc.Controller;
import play.server.ServletWrapper;

public abstract class Base extends Controller {
	
	protected static final int PAGE_SIZE = 20;
	
	public static Gson gson() {	
		Gson gson = new GsonBuilder().registerTypeAdapter(java.util.Date.class, new	
				JsonDeserializer<java.util.Date>() {
				@Override
				public java.util.Date deserialize(com.google.gson.JsonElement p1,
						java.lang.reflect.Type p2,com.google.gson.JsonDeserializationContext p3) {
					return new java.util.Date(p1.getAsLong());
				}}).registerTypeAdapter(java.util.Date.class, new
				JsonSerializer<java.util.Date>() {
			@Override
			public JsonElement serialize(java.util.Date src, Type typeOfSrc,
					com.google.gson.JsonSerializationContext context) {
				return new JsonPrimitive(src.getTime());
			}
		}).create();
		return gson;
	}
	
	protected static HttpServletResponse getHttpServletResponse() { 
        return (HttpServletResponse) request.args.get(ServletWrapper.SERVLET_RES);
    }
	
}